using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace ShellAnywhere.Model
{
	public class HistoryMgr
	{
		#region ctors
		public HistoryMgr() 
		{
			_CommandHistory = new List<string>();
			_CurrCommandIndex = 0;
		}
		#endregion ctors

		#region props
		public string LastCommand 
		{ 
			get 
			{
				string lastCommand = null;
				if (_CommandHistory.Count > 0) 
					lastCommand = _CommandHistory[_CommandHistory.Count - 1];
				return lastCommand;
			} 
		}
		public string CurrCommand 
		{ 
			get 
			{
				string currCommand = null;
				if (_CommandHistory.Count > 0)
					currCommand = _CommandHistory[_CurrCommandIndex];
				return currCommand;
			} 
		}
		#endregion props

		#region methods
		public string IncrIndex()
		{
			if (++_CurrCommandIndex >= _CommandHistory.Count)
				_CurrCommandIndex = _CommandHistory.Count - 1;
			return CurrCommand;
		}
		public string DecrIndex()
		{
			if (--_CurrCommandIndex <= 0)
				_CurrCommandIndex = 0;
			return CurrCommand;
		}
		public void AddCommand(string commandText)
		{
			if (LastCommand != commandText)
			{
				_CommandHistory.Add(commandText);
				_CurrCommandIndex = _CommandHistory.Count;
			}
		}
		#endregion methods

		#region fields
		private List<string> _CommandHistory;
		private int _CurrCommandIndex;
		#endregion fields
	}
}
